package com.nameless.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.Collections;

/**
 * @author keluoyisi
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "全局统一返回结果")
public class Result<T> {
    @ApiModelProperty(value = "返回码")
    private Integer code;
    @ApiModelProperty(value = "返回消息")
    private String msg;
    @ApiModelProperty(value = "返回数据")
    private T data;
    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> Result<T> success(T object) {
        Result<T> r = new Result<>();
        r.data = object;
        r.code = 200;
        return r;
    }

    public static <T> Result<T> success(String msg, T data){
        Result<T> r = new Result<>();
        r.msg = msg;
        r.data = data;
        r.code = 200;
        return r;
    }

    public static <T> Result<T> error(String msg) {
        Result<T> result = new Result<>();
        result.msg = msg;
        result.code = 500;
        return result;
    }

    public static <T> Result<T> error(String msg,T data) {
        Result<T> result = new Result<>();
        result.msg = msg;
        result.data = data;
        result.code = 500;
        return result;
    }

}